home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / lib / perl5 / Glib / xsapi.pod < prev   
Encoding:
Text File  |  2012-02-20  |  38.9 KB  |  1,189 lines

  1.  
  2. =head1 NAME
  3.  
  4. Glib::xsapi - internal API reference for GPerl.
  5.  
  6. =head1 SYNOPSIS
  7.  
  8.  #include <gperl.h>
  9.  
  10. =head1 DESCRIPTION
  11.  
  12. This is the binding developer's API reference for GPerl, automatically
  13. generated from the xs source files.  This header defines the public
  14. interface for use when creating new Perl language bindings for GLib-based C
  15. libraries.
  16.  
  17. gperl.h includes for you all the headers needed for writing XSUBs 
  18. (EXTERN.h, perl.h, and XSUB.h), as well as all of GLib (via glib-object.h).
  19.  
  20. =head1 API
  21.  
  22. =cut
  23.  
  24. =head2 Miscellaneous
  25.  
  26. Various useful utilities defined in Glib.xs.
  27.  
  28. =over
  29.  
  30. =item GPERL_CALL_BOOT(name)
  31.  
  32. call the boot code of a module by symbol rather than by name.
  33.  
  34. in a perl extension which uses several xs files but only one pm, you
  35. need to bootstrap the other xs files in order to get their functions
  36. exported to perl.  if the file has MODULE = Foo::Bar, the boot symbol
  37. would be boot_Foo__Bar.
  38.  
  39. =item void _gperl_call_XS (pTHX_ void (*subaddr) (pTHX_ CV *), CV * cv, SV ** mark);
  40.  
  41. never use this function directly.  see C<GPERL_CALL_BOOT>.
  42.  
  43. for the curious, this calls a perl sub by function pointer rather than
  44. by name; call_sv requires that the xsub already be registered, but we
  45. need this to call a function which will register xsubs.  this is an
  46. evil hack and should not be used outside of the GPERL_CALL_BOOT macro.
  47. it's implemented as a function to avoid code size bloat, and exported
  48. so that extension modules can pull the same trick.
  49.  
  50. =cut
  51.  
  52. =item gpointer gperl_alloc_temp (int nbytes)
  53.  
  54. Allocate and return a pointer to an I<nbytes>-long, zero-initialized,
  55. temporary buffer that will be reaped at the next garbage collection sweep.
  56. This is handy for allocating things that need to be alloc'ed before a croak
  57. (since croak doesn't return and give you the chance to free them).  The
  58. trick is that the memory is allocated in a mortal perl scalar.  See the
  59. perl online manual for notes on using this technique.
  60.  
  61. Do B<not> under any circumstances attempt to call g_free(), free(), or any
  62. other deallocator on this pointer, or you will crash the interpreter.
  63.  
  64. =cut
  65.  
  66. =item gchar *gperl_filename_from_sv (SV *sv)
  67.  
  68. Return a localized version of the filename in the sv, using
  69. g_filename_from_utf8 (and consequently this function might croak). The
  70. memory is allocated using gperl_alloc_temp.
  71.  
  72. =cut
  73.  
  74. =item SV *gperl_sv_from_filename (const gchar *filename)
  75.  
  76. Convert the filename into an utf8 string as used by gtk/glib and perl.
  77.  
  78. =cut
  79.  
  80. =item gboolean gperl_str_eq (const char * a, const char * b);
  81.  
  82. Compare a pair of ascii strings, considering '-' and '_' to be equivalent.
  83. Used for things like enum value nicknames and signal names.
  84.  
  85. =cut
  86.  
  87. =item guint gperl_str_hash (gconstpointer key)
  88.  
  89. Like g_str_hash(), but considers '-' and '_' to be equivalent.
  90.  
  91. =cut
  92.  
  93. =item GPerlArgv * gperl_argv_new ()
  94.  
  95. Creates a new Perl argv object whose members can then be passed to functions
  96. that request argc and argv style arguments.
  97.  
  98. If the called function(s) modified argv, you can call L<gperl_argv_update> to
  99. update Perl's @ARGV in the same way.
  100.  
  101. Remember to call L<gperl_argv_free> when you're done.
  102.  
  103. =cut
  104.  
  105. =item void gperl_argv_update (GPerlArgv *pargv)
  106.  
  107. Updates @ARGV to resemble the stored argv array.
  108.  
  109. =cut
  110.  
  111. =item void gperl_argv_free (GPerlArgv *pargv)
  112.  
  113. Frees any resources associated with I<pargv>.
  114.  
  115. =cut
  116.  
  117. =item char * gperl_format_variable_for_output (SV * sv)
  118.  
  119. Formats the variable stored in I<sv> for output in error messages.  Like
  120. SvPV_nolen(), but ellipsizes real strings (i.e., not stringified references)
  121. at 20 chars to trim things down for error messages.
  122.  
  123. =cut
  124.  
  125. =item gboolean gperl_sv_is_defined (SV *sv)
  126.  
  127. Checks the SV I<sv> for definedness just like Perl's I<defined()> would do.
  128. Most importantly, it correctly handles "magical" SVs, unlike bare I<SvOK>.
  129. It's also NULL-safe.
  130.  
  131. =cut
  132.  
  133. =item void gperl_hv_take_sv (HV *hv, const char *key, size_t key_length, SV *sv)
  134.  
  135. Tries to store I<sv> in I<hv>.  Decreases I<sv>'s reference count if something
  136. goes wrong.
  137.  
  138. =cut
  139.  
  140. =back
  141.  
  142. =cut
  143.  
  144. =head2 GError Exception Objects
  145.  
  146. GError is a facility for propagating run-time error / exception information
  147. around in C, which is a language without native support for exceptions.
  148. GError uses a simple error code, usually defined as an enum.  Since the
  149. enums will overlap, GError includes the GQuark corresponding to a particular
  150. error "domain" to tell you which error codes will be used.  There's also a
  151. string containing a specific error message.  The strings are arbitrary, and
  152. may be translated, but the domains and codes are definite.
  153.  
  154. Perl has native support for exceptions, using C<eval> as "try", C<croak> or
  155. C<die> as "throw", and C<< if ($@) >> as "catch".  C<$@> may, in fact, be
  156. any scalar, including blessed objects.
  157.  
  158. So, GPerl maps GLib's GError to Perl exceptions.
  159.  
  160. Since, as we described above, error messages are not guaranteed to be unique
  161. everywhere, we need to support the use of the error domains and codes.
  162. The obvious choice here is to use exception objects; however, to support
  163. blessed exception objects, we must perform a little bit of black magic in
  164. the bindings.   There is no built-in association between an error domain
  165. quark and the GType of the corresponding error code enumeration, so the
  166. bindings supply both of these when specifying the name of the package into
  167. which to bless exceptions of this domain.  All GError-based exceptions 
  168. derive from Glib::Error, of course, and this base class provides all of the
  169. functionality, including stringification.
  170.  
  171. All you'll really ever need to do is register error domains with
  172. C<gperl_register_error_domain>, and throw errors with C<gperl_croak_gerror>.
  173.  
  174. =over
  175.  
  176. =cut
  177.  
  178. =item void gperl_register_error_domain (GQuark domain, GType error_enum, const char * package)
  179.  
  180. Tell the bindings to bless GErrors with error->domain == I<domain> into
  181. I<package>, and use I<error_enum> to find the nicknames for the error codes.
  182. This will call C<gperl_set_isa> on I<package> to add "Glib::Error" to
  183. I<package>'s @ISA.
  184.  
  185. I<domain> may not be 0, and I<package> may not be NULL; what would be the 
  186. point?  I<error_enum> may be 0, in which case you'll get no fancy stringified
  187. error values.
  188.  
  189. =cut
  190.  
  191. =item SV * gperl_sv_from_gerror (GError * error)
  192.  
  193. You should rarely, if ever, need to call this function.  This is what turns
  194. a GError into a Perl object.
  195.  
  196. =cut
  197.  
  198. =item gperl_gerror_from_sv (SV * sv, GError ** error)
  199.  
  200. You should rarely need this function.  This parses a perl data structure into
  201. a GError.  If I<sv> is undef (or the empty string), sets *I<error> to NULL,
  202. otherwise, allocates a new GError with C<g_error_new_literal()> and writes
  203. through I<error>; the caller is responsible for calling C<g_error_free()>.
  204. (gperl_croak_gerror() does this, for example.)
  205.  
  206. =cut
  207.  
  208. =item void gperl_croak_gerror (const char * ignored, GError * err)
  209.  
  210. Croak with an exception based on I<err>.  I<err> may not be NULL.  I<ignored>
  211. exists for backward compatibility, and is, well, ignored.  This function
  212. calls croak(), which does not return.
  213.  
  214. Since croak() does not return, this function handles the magic behind 
  215. not leaking the memory associated with the #GError.  To use this you'd
  216. do something like
  217.  
  218.  PREINIT:
  219.    GError * error = NULL;
  220.  CODE:
  221.    if (!funtion_that_can_fail (something, &error))
  222.       gperl_croak_gerror (NULL, error);
  223.  
  224. It's just that simple!
  225.  
  226. =cut
  227.  
  228. =back
  229.  
  230. =cut
  231.  
  232. =head2 GLog
  233.  
  234. GLib has a message logging mechanism which it uses for the g_return_if_fail()
  235. assertion macros, etc.; it's really versatile and allows you to set various
  236. levels to be fatal and whatnot.  Libraries use these for various types of
  237. message reporting.
  238.  
  239. These functions let you reroute those messages from Perl.  By default, 
  240. the warning, critical, and message levels go through perl's warn(), and
  241. fatal ones go through croak().  [i'm not sure that these get to croak()
  242. before GLib abort()s on them...]
  243.  
  244. =over
  245.  
  246. =cut
  247.  
  248. =item gint gperl_handle_logs_for (const gchar * log_domain)
  249.  
  250. Route all g_logs for I<log_domain> through gperl's log handling.  You'll
  251. have to register domains in each binding submodule, because there's no way
  252. we can know about them down here.
  253.  
  254. And, technically, this traps all the predefined log levels, not any of
  255. the ones you (or your library) may define for yourself.
  256.  
  257. =cut
  258.  
  259. =back
  260.  
  261. =cut
  262.  
  263. =head2 GType / GEnum / GFlags
  264.  
  265. =over
  266.  
  267. =cut
  268.  
  269. =item void gperl_register_fundamental (GType gtype, const char * package)
  270.  
  271. register a mapping between I<gtype> and I<package>.  this is for "fundamental"
  272. types which have no other requirements for metadata storage, such as GEnums,
  273. GFlags, or real GLib fundamental types like G_TYPE_INT, G_TYPE_FLOAT, etc.
  274.  
  275. =cut
  276.  
  277. =item void gperl_register_fundamental_alias (GType gtype, const char * package)
  278.  
  279. Makes I<package> an alias for I<type>.  This means that the package name
  280. specified by I<package> will be mapped to I<type> by
  281. I<gperl_fundamental_type_from_package>, but
  282. I<gperl_fundamental_package_from_type> won't map I<type> to I<package>.  This
  283. is useful if you want to change the canonical package name of a type while
  284. preserving backwards compatibility with code which uses I<package> to specify
  285. I<type>.
  286.  
  287. In order for this to make sense, another package name should be registered for
  288. I<type> with I<gperl_register_fundamental> or
  289. I<gperl_register_fundamental_full>.
  290.  
  291. =cut
  292.  
  293. =item GPerlValueWrapperClass
  294.  
  295. Specifies the vtable that is to be used to convert fundamental types to and
  296. from Perl variables.
  297.  
  298.   typedef struct _GPerlValueWrapperClass GPerlValueWrapperClass;
  299.   struct _GPerlValueWrapperClass {
  300.           GPerlValueWrapFunc   wrap;
  301.           GPerlValueUnwrapFunc unwrap;
  302.   };
  303.  
  304. The members are function pointers, each of which serves a specific purpose:
  305.  
  306. =over
  307.  
  308. =item GPerlValueWrapFunc
  309.  
  310. Turns I<value> into an SV.  The caller assumes ownership of the SV.  I<value>
  311. is not to be modified.
  312.  
  313.   typedef SV*  (*GPerlValueWrapFunc)   (const GValue * value);
  314.  
  315. =item GPerlValueUnwrapFunc
  316.  
  317. Turns I<sv> into its fundamental representation and stores the result in the
  318. pre-configured I<value>.  I<value> must not be overwritten; instead one of the
  319. various C<g_value_set_*()> functions must be used or the C<value-E<gt>data>
  320. pointer must be modifed directly.
  321.  
  322.   typedef void (*GPerlValueUnwrapFunc) (GValue       * value,
  323.                                         SV           * sv);
  324.  
  325. =back
  326.  
  327. =cut
  328.  
  329. =item void gperl_register_fundamental_full (GType gtype, const char * package, GPerlValueWrapperClass * wrapper_class)
  330.  
  331. Like L<gperl_register_fundamental>, registers a mapping between I<gtype> and
  332. I<package>.  In addition, this also installs the function pointers in
  333. I<wrapper_class> as the handlers for the type.  See L<GPerlValueWrapperClass>.
  334.  
  335. I<gperl_register_fundamental_full> does not copy the contents of
  336. I<wrapper_class> -- it assumes that I<wrapper_class> is statically allocated
  337. and that it will be valid for the whole lifetime of the program.
  338.  
  339. =cut
  340.  
  341. =item GType gperl_fundamental_type_from_package (const char * package)
  342.  
  343. look up the GType corresponding to a I<package> registered by
  344. gperl_register_fundamental().
  345.  
  346. =cut
  347.  
  348. =item const char * gperl_fundamental_package_from_type (GType gtype)
  349.  
  350. look up the package corresponding to a I<gtype> registered by
  351. gperl_register_fundamental().
  352.  
  353. =cut
  354.  
  355. =item GPerlValueWrapperClass * gperl_fundamental_wrapper_class_from_type (GType gtype)
  356.  
  357. look up the wrapper class corresponding to a I<gtype> that has previously been
  358. registered with gperl_register_fundamental_full().
  359.  
  360. =cut
  361.  
  362. =item gboolean gperl_try_convert_enum (GType gtype, SV * sv, gint * val)
  363.  
  364. return FALSE if I<sv> can't be mapped to a valid member of the registered
  365. enum type I<gtype>; otherwise, return TRUE write the new value to the
  366. int pointed to by I<val>.
  367.  
  368. you'll need this only in esoteric cases.
  369.  
  370. =cut
  371.  
  372. =item gint gperl_convert_enum (GType type, SV * val)
  373.  
  374. croak if I<val> is not part of I<type>, otherwise return corresponding value
  375.  
  376. =cut
  377.  
  378. =item SV * gperl_convert_back_enum_pass_unknown (GType type, gint val)
  379.  
  380. return a scalar containing the nickname of the enum value I<val>, or the
  381. integer value of I<val> if I<val> is not a member of the enum I<type>.
  382.  
  383. =cut
  384.  
  385. =item SV * gperl_convert_back_enum (GType type, gint val)
  386.  
  387. return a scalar which is the nickname of the enum value val, or croak if
  388. val is not a member of the enum.
  389.  
  390. =cut
  391.  
  392. =item gboolean gperl_try_convert_flag (GType type, const char * val_p, gint * val)
  393.  
  394. like gperl_try_convert_enum(), but for GFlags.
  395.  
  396. =cut
  397.  
  398. =item gint gperl_convert_flag_one (GType type, const char * val)
  399.  
  400. croak if I<val> is not part of I<type>, otherwise return corresponding value.
  401.  
  402. =cut
  403.  
  404. =item gint gperl_convert_flags (GType type, SV * val)
  405.  
  406. collapse a list of strings to an integer with all the correct bits set,
  407. croak if anything is invalid.
  408.  
  409. =cut
  410.  
  411. =item SV * gperl_convert_back_flags (GType type, gint val)
  412.  
  413. convert a bitfield to a list of strings.
  414.  
  415. =cut
  416.  
  417. =back
  418.  
  419. =head2 Inheritance management
  420.  
  421. =over
  422.  
  423. =item void gperl_set_isa (const char * child_package, const char * parent_package)
  424.  
  425. tell perl that I<child_package> inherits I<parent_package>, after whatever else
  426. is already there.  equivalent to C<< push @{$parent_package}::ISA, $child_package; >>
  427.  
  428. =cut
  429.  
  430. =item void gperl_prepend_isa (const char * child_package, const char * parent_package)
  431.  
  432. tell perl that I<child_package> inherits I<parent_package>, but before whatever
  433. else is already there.  equivalent to C<< unshift @{$parent_package}::ISA, $child_package; >>
  434.  
  435. =cut
  436.  
  437. =item GType gperl_type_from_package (const char * package)
  438.  
  439. Look up the GType associated with I<package>, regardless of how it was
  440. registered.  Returns 0 if no mapping can be found.
  441.  
  442. =cut
  443.  
  444. =item const char * gperl_package_from_type (GType gtype)
  445.  
  446. Look up the name of the package associated with I<gtype>, regardless of how it
  447. was registered.  Returns NULL if no mapping can be found.
  448.  
  449. =cut
  450.  
  451. =back
  452.  
  453. =head2 Boxed type support for SV
  454.  
  455. In order to allow GValues to hold perl SVs we need a GBoxed wrapper.
  456.  
  457. =over
  458.  
  459. =item GPERL_TYPE_SV
  460.  
  461. Evaluates to the GType for SVs.  The bindings register a mapping between
  462. GPERL_TYPE_SV and the package 'Glib::Scalar' with gperl_register_boxed().
  463.  
  464. =item SV * gperl_sv_copy (SV * sv)
  465.  
  466. implemented as C<< newSVsv (sv) >>.
  467.  
  468. =item void gperl_sv_free (SV * sv)
  469.  
  470. implemented as C<< SvREFCNT_dec (sv) >>.
  471.  
  472. =cut
  473.  
  474. =back
  475.  
  476. =head2 UTF-8 strings with gchar
  477.  
  478. By convention, gchar* is assumed to point to UTF8 string data,
  479. and char* points to ascii string data.  Here we define a pair of
  480. wrappers for the boilerplate of upgrading Perl strings.  They
  481. are implemented as functions rather than macros, because comma
  482. expressions in macros are not supported by all compilers.
  483.  
  484. These functions should be used instead of newSVpv and SvPV_nolen
  485. in all cases which deal with gchar* types.
  486.  
  487. =over
  488.  
  489. =item gchar * SvGChar (SV * sv)
  490.  
  491. extract a UTF8 string from I<sv>.
  492.  
  493. =cut
  494.  
  495. =item SV * newSVGChar (const gchar * str)
  496.  
  497. copy a UTF8 string into a new SV.  if str is NULL, returns &PL_sv_undef.
  498.  
  499. =cut
  500.  
  501. =back
  502.  
  503. =head2 64 bit integers
  504.  
  505. On 32 bit machines and even on some 64 bit machines, perl's IV/UV data type can
  506. only hold 32 bit values.  The following functions therefore convert 64 bit
  507. integers to and from Perl strings if normal IV/UV conversion does not suffice.
  508.  
  509. =over
  510.  
  511. =item gint64 SvGInt64 (SV *sv)
  512.  
  513. Converts the string in I<sv> to a signed 64 bit integer.  If appropriate, uses
  514. C<SvIV> instead.
  515.  
  516. =cut
  517.  
  518. =item SV * newSVGInt64 (gint64 value)
  519.  
  520. Creates a PV from the signed 64 bit integer in I<value>.  If appropriate, uses
  521. C<newSViv> instead.
  522.  
  523. =cut
  524.  
  525. =item guint64 SvGUInt64 (SV *sv)
  526.  
  527. Converts the string in I<sv> to an unsigned 64 bit integer.  If appropriate,
  528. uses C<SvUV> instead.
  529.  
  530. =cut
  531.  
  532. =item SV * newSVGUInt64 (guint64 value)
  533.  
  534. Creates a PV from the unsigned 64 bit integer in I<value>.  If appropriate,
  535. uses C<newSVuv> instead.
  536.  
  537. =cut
  538.  
  539. =back
  540.  
  541. =cut
  542.  
  543. =head2 GBoxed
  544.  
  545. =over
  546.  
  547. =item GPerlBoxedWrapperClass
  548.  
  549. Specifies the vtable of functions to be used for bringing boxed types in
  550. and out of perl.  The structure is defined like this:
  551.  
  552.  typedef struct _GPerlBoxedWrapperClass GPerlBoxedWrapperClass;
  553.  struct _GPerlBoxedWrapperClass {
  554.           GPerlBoxedWrapFunc    wrap;
  555.           GPerlBoxedUnwrapFunc  unwrap;
  556.           GPerlBoxedDestroyFunc destroy;
  557.  };
  558.  
  559. The members are function pointers, each of which serves a specific purpose:
  560.  
  561. =over
  562.  
  563. =item GPerlBoxedWrapFunc
  564.  
  565. turn a boxed pointer into an SV.  gtype is the type of the boxed pointer,
  566. and package is the package to which that gtype is registered (the lookup
  567. has already been done for you at this point).  if own is true, the wrapper
  568. is responsible for freeing the object; if it is false, some other code 
  569. owns the object and you must NOT free it.
  570.  
  571.  typedef SV*      (*GPerlBoxedWrapFunc)    (GType        gtype,
  572.                                             const char * package,
  573.                                             gpointer     boxed,
  574.                                             gboolean     own);
  575.  
  576. =item GPerlBoxedUnwrapFunc
  577.  
  578. turn an SV into a boxed pointer.  like GPerlBoxedWrapFunc, gtype and package
  579. are the registered type pair, already looked up for you (in the process of
  580. finding the proper wrapper class).  sv is the sv to unwrap.
  581.  
  582.  typedef gpointer (*GPerlBoxedUnwrapFunc)  (GType        gtype,
  583.                                             const char * package,
  584.                                             SV         * sv);
  585.  
  586. =item GPerlBoxedDestroyFunc
  587.  
  588. this will be called by Glib::Boxed::DESTROY, when the wrapper is destroyed.
  589. it is a hook that allows you to destroy an object owned by the wrapper;
  590. note, however, that you will have had to keep track yourself of whether
  591. the object was to be freed.
  592.  
  593.  typedef void     (*GPerlBoxedDestroyFunc) (SV         * sv);
  594.  
  595. =back
  596.  
  597. =cut
  598.  
  599. =item void gperl_register_boxed (GType gtype, const char * package, GPerlBoxedWrapperClass * wrapper_class)
  600.  
  601. Register a mapping between the GBoxed derivative I<gtype> and I<package>.  The
  602. specified, I<wrapper_class> will be used to wrap and unwrap objects of this
  603. type; you may pass NULL to use the default wrapper (the same one returned by
  604. gperl_default_boxed_wrapper_class()).
  605.  
  606. In normal usage, the standard opaque wrapper supplied by the library is
  607. sufficient and correct.  In some cases, however, you want a boxed type to map
  608. directly to a native perl type; for example, some struct may be more
  609. appropriately represented as a hash in perl.  Since the most necessary place
  610. for this conversion to happen is in gperl_value_from_sv() and
  611. gperl_sv_from_value(), the only reliable and robust way to implement this 
  612. is a hook into gperl_get_boxed_check() and gperl_new_boxed(); that is
  613. exactly the purpose of I<wrapper_class>.  See C<GPerlBoxedWrapperClass>.
  614.  
  615. I<gperl_register_boxed> does not copy the contents of I<wrapper_class> -- it
  616. assumes that I<wrapper_class> is statically allocated and that it will be valid
  617. for the whole lifetime of the program.
  618.  
  619. =cut
  620.  
  621. =item void gperl_register_boxed_alias (GType gtype, const char * package)
  622.  
  623. Makes I<package> an alias for I<type>.  This means that the package name
  624. specified by I<package> will be mapped to I<type> by
  625. I<gperl_boxed_type_from_package>, but I<gperl_boxed_package_from_type> won't
  626. map I<type> to I<package>.  This is useful if you want to change the canonical
  627. package name of a type while preserving backwards compatibility with code which
  628. uses I<package> to specify I<type>.
  629.  
  630. In order for this to make sense, another package name should be registered for
  631. I<type> with I<gperl_register_boxed>.
  632.  
  633. =cut
  634.  
  635. =item GType gperl_boxed_type_from_package (const char * package)
  636.  
  637. Look up the GType associated with package I<package>.  Returns 0 if I<type> is
  638. not registered.
  639.  
  640. =cut
  641.  
  642. =item const char * gperl_boxed_package_from_type (GType type)
  643.  
  644. Look up the package associated with GBoxed derivative I<type>.  Returns NULL if
  645. I<type> is not registered.
  646.  
  647. =cut
  648.  
  649. =item GPerlBoxedWrapperClass * gperl_default_boxed_wrapper_class (void)
  650.  
  651. get a pointer to the default wrapper class; handy if you want to use
  652. the normal wrapper, with minor modifications.  note that you can just
  653. pass NULL to gperl_register_boxed(), so you really only need this in
  654. fringe cases.
  655.  
  656. =cut
  657.  
  658. =item SV * gperl_new_boxed (gpointer boxed, GType gtype, gboolean own)
  659.  
  660. Export a GBoxed derivative to perl, according to whatever
  661. GPerlBoxedWrapperClass is registered for I<gtype>.  In the default
  662. implementation, this means wrapping an opaque perl object around the pointer
  663. to a small wrapper structure which stores some metadata, such as whether
  664. the boxed structure should be destroyed when the wrapper is destroyed
  665. (controlled by I<own>; if the wrapper owns the object, the wrapper is in
  666. charge of destroying it's data).
  667.  
  668. =cut
  669.  
  670. =item SV * gperl_new_boxed_copy (gpointer boxed, GType gtype)
  671.  
  672. Create a new copy of I<boxed> and return an owner wrapper for it.
  673. I<boxed> may not be NULL.  See C<gperl_new_boxed>.
  674.  
  675. =cut
  676.  
  677. =item gpointer gperl_get_boxed_check (SV * sv, GType gtype)
  678.  
  679. Extract the boxed pointer from a wrapper; croaks if the wrapper I<sv> is not
  680. blessed into a derivative of the expected I<gtype>.  Does not allow undef.
  681.  
  682. =cut
  683.  
  684. =back
  685.  
  686. =cut
  687.  
  688. =head2 GObject
  689.  
  690. To deal with the intricate interaction of the different reference-counting
  691. semantics of Perl objects versus GObjects, the bindings create a combined
  692. PerlObject+GObject, with the GObject's pointer in magic attached to the Perl
  693. object, and the Perl object's pointer in the GObject's user data.  Thus it's
  694. not really a "wrapper", but we refer to it as one, because "combined Perl
  695. object + GObject" is a cumbersome and confusing mouthful.
  696.  
  697. GObjects are represented as blessed hash references.  The GObject user data
  698. mechanism is not typesafe, and thus is used only for unsigned integer values;
  699. the Perl-level hash is available for any type of user data.  The combined
  700. nature of the wrapper means that data stored in the hash will stick around as
  701. long as the object is alive.
  702.  
  703. Since the C pointer is stored in attached magic, the C pointer is not available
  704. to the Perl developer via the hash object, so there's no need to worry about
  705. breaking it from perl.
  706.  
  707. Propers go to Marc Lehmann for dreaming most of this up.
  708.  
  709. =over
  710.  
  711. =cut
  712.  
  713. =item void gperl_register_object (GType gtype, const char * package)
  714.  
  715. tell the GPerl type subsystem what Perl package corresponds with a given
  716. GObject by GType.  automagically sets up @I<package>::ISA for you.
  717.  
  718. note that @ISA will not be created for gtype until gtype's parent has
  719. been registered.  if you are experiencing strange problems with a class'
  720. @ISA not being set up, change the order in which you register them.
  721.  
  722. =cut
  723.  
  724. =item void gperl_register_object_alias (GType gtype, const char * package)
  725.  
  726. Makes I<package> an alias for I<type>.  This means that the package name
  727. specified by I<package> will be mapped to I<type> by
  728. I<gperl_object_type_from_package>, but I<gperl_object_package_from_type> won't
  729. map I<type> to I<package>.  This is useful if you want to change the canonical
  730. package name of a type while preserving backwards compatibility with code which
  731. uses I<package> to specify I<type>.
  732.  
  733. In order for this to make sense, another package name should be registered for
  734. I<type> with I<gperl_register_object>.
  735.  
  736. =cut
  737.  
  738. =item void gperl_register_sink_func (GType gtype, GPerlObjectSinkFunc func)
  739.  
  740. Tell gperl_new_object() to use I<func> to claim ownership of objects derived
  741. from I<gtype>.
  742.  
  743. gperl_new_object() always refs a GObject when wrapping it for the first time.
  744. To have the Perl wrapper claim ownership of a GObject as part of
  745. gperl_new_object(), you unref the object after ref'ing it. however, different
  746. GObject subclasses have different ways to claim ownership; for example,
  747. GtkObject simply requires you to call gtk_object_sink().  To make this concept
  748. generic, this function allows you to register a function to be called when then
  749. wrapper should claim ownership of the object.  The I<func> registered for a
  750. given I<type> will be called on any object for which C<< g_type_isa
  751. (G_TYPE_OBJECT (object), type) >> succeeds.
  752.  
  753. If no sinkfunc is found for an object, g_object_unref() will be used.
  754.  
  755. Even though GObjects don't need sink funcs, we need to have them in Glib
  756. as a hook for upstream objects.  If we create a GtkObject (or any
  757. other type of object which uses a different way to claim ownership) via
  758. Glib::Object->new, any upstream wrappers, such as gtk2perl_new_object(), will
  759. B<not> be called.  Having a sink func facility down here enables us always to
  760. do the right thing.
  761.  
  762. =cut
  763.  
  764. =item void gperl_object_set_no_warn_unreg_subclass (GType gtype, gboolean nowarn)
  765.  
  766. In versions 1.00 through 1.10x of Glib, the bindings required all types
  767. to be registered ahead of time.  Upon encountering an unknown type, the
  768. bindings would emit a warning to the effect of "unknown type 'Foo';
  769. representing as first known parent type 'Bar'".  However, for some
  770. types, such as GtkStyle or GdkGC, the actual object returned is an
  771. instance of a child type of a private implementation (e.g., a theme
  772. engine ("BlueCurveStyle") or gdk backend ("GdkGCX11")); we neither can
  773. nor should have registered names for these types.  Therefore, it is
  774. possible to tell the bindings not to warn about these unregistered
  775. subclasses, and simply represent them as the parent type.
  776.  
  777. With 1.12x, the bindings will automatically register unknown classes
  778. into the namespace Glib::Object::_Unregistered to avoid possible
  779. breakage resulting from unknown ancestors of known children.  To
  780. preserve the old registered-as-unregistered behavior, the value
  781. installed by this function is used to prevent the _Unregistered mapping
  782. for such private backend classes.
  783.  
  784.  
  785. Note: this assumes I<gtype> has already been registered with
  786. gperl_register_object().
  787.  
  788. =cut
  789.  
  790. =item const char * gperl_object_package_from_type (GType gtype)
  791.  
  792. Get the package corresponding to I<gtype>.  If I<gtype> is not a GObject
  793. or GInterface, returns NULL.  If I<gtype> is not registered to a package
  794. name, a new name of the form C<Glib::Object::_Unregistered::$c_type_name>
  795. will be created, used to register the class, and then returned.
  796.  
  797. =cut
  798.  
  799. =item HV * gperl_object_stash_from_type (GType gtype)
  800.  
  801. Get the stash corresponding to I<gtype>; returns NULL if I<gtype> is
  802. not registered.  The stash is useful for C<bless>ing.
  803.  
  804. =cut
  805.  
  806. =item GType gperl_object_type_from_package (const char * package)
  807.  
  808. Inverse of gperl_object_package_from_type(),  returns 0 if I<package>
  809. is not registered.
  810.  
  811. =cut
  812.  
  813. =item SV * gperl_new_object (GObject * object, gboolean own)
  814.  
  815. Use this function to get the perl part of a GObject.  If I<object>
  816. has never been seen by perl before, a new, empty perl object will
  817. be created and added to a private key under I<object>'s qdata.  If
  818. I<object> already has a perl part, a new reference to it will be
  819. created. The gobject + perl object together form a combined object that
  820. is properly refcounted, i.e. both parts will stay alive as long as at
  821. least one of them is alive, and only when both perl object and gobject are
  822. no longer referenced will both be freed.
  823.  
  824. The perl object will be blessed into the package corresponding to the GType
  825. returned by calling G_OBJECT_TYPE() on I<object>; if that class has not
  826. been registered via gperl_register_object(), this function will emit a
  827. warning to that effect (with warn()), and attempt to bless it into the
  828. first known class in the object's ancestry.  Since Glib::Object is
  829. already registered, you'll get a Glib::Object if you are lazy, and thus
  830. this function can fail only if I<object> isn't descended from GObject,
  831. in which case it croaks.  (In reality, if you pass a non-GObject to this
  832. function, you'll be lucky if you don't get a segfault, as there's not
  833. really a way to trap that.)  In practice these warnings can be unavoidable,
  834. so you can use gperl_object_set_no_warn_unreg_subclass() to quell them
  835. on a class-by-class basis.
  836.  
  837. However, when perl code is calling a GObject constructor (any function
  838. which returns a new GObject), call gperl_new_object() with I<own> set to
  839. %TRUE; this will cause the first matching sink function to be called
  840. on the GObject to claim ownership of that object, so that it will be
  841. destroyed when the perl object goes out of scope. The default sink func
  842. is g_object_unref(); other types should supply the proper function;
  843. e.g., GtkObject should use gtk_object_sink() here.
  844.  
  845. Returns the blessed perl object, or #&PL_sv_undef if object was #NULL.
  846.  
  847. =cut
  848.  
  849. =item GObject * gperl_get_object (SV * sv)
  850.  
  851. retrieve the GObject pointer from a Perl object.  Returns NULL if I<sv> is not
  852. linked to a GObject.
  853.  
  854. Note, this one is not safe -- in general you want to use
  855. gperl_get_object_check().
  856.  
  857. =cut
  858.  
  859. =item GObject * gperl_get_object_check (SV * sv, GType gtype);
  860.  
  861. croaks if I<sv> is undef or is not blessed into the package corresponding
  862. to I<gtype>.  use this for bringing parameters into xsubs from perl.
  863. Returns the same as gperl_get_object() (provided it doesn't croak first).
  864.  
  865. =cut
  866.  
  867. =item SV * gperl_object_check_type (SV * sv, GType gtype)
  868.  
  869. Essentially the same as gperl_get_object_check().
  870.  
  871. This croaks if the types aren't compatible.
  872.  
  873. =cut
  874.  
  875. =item typedef GObject GObject_noinc
  876.  
  877. =item typedef GObject GObject_ornull
  878.  
  879. =item newSVGObject(obj)
  880.  
  881. =item newSVGObject_noinc(obj)
  882.  
  883. =item SvGObject(sv)
  884.  
  885. =item SvGObject_ornull(sv)
  886.  
  887.  
  888. =back
  889.  
  890. =cut
  891.  
  892. =head2 GValue
  893.  
  894. GValue is GLib's generic value container, and it is because of GValue that the
  895. run time type handling of GObject parameters and GClosure marshaling can
  896. function, and most usages of these functions will be from those two points.
  897.  
  898. Client code will run into uses for gperl_sv_from_value() and
  899. gperl_value_from_sv() when trying to convert lists of parameters into GValue
  900. arrays and the like.
  901.  
  902. =over
  903.  
  904. =cut
  905.  
  906. =item gboolean gperl_value_from_sv (GValue * value, SV * sv)
  907.  
  908. set a I<value> from a whatever is in I<sv>.  I<value> must be initialized 
  909. so the code knows what kind of value to coerce out of I<sv>.
  910.  
  911. Return value is always TRUE; if the code knows how to perform the conversion,
  912. it croaks.  (The return value is for backward compatibility.) In reality,
  913. this really ought to always succeed; a failed conversion should be considered
  914. a bug or unimplemented code!
  915.  
  916. =cut
  917.  
  918. =item SV * gperl_sv_from_value (const GValue * value)
  919.  
  920. Coerce whatever is in I<value> into a perl scalar and return it.
  921.  
  922. Croaks if the code doesn't know how to perform the conversion.
  923.  
  924. =cut
  925.  
  926. =back
  927.  
  928. =cut
  929.  
  930. =head2 GClosure / GPerlClosure
  931.  
  932. GPerlClosure is a wrapper around the gobject library's GClosure with
  933. special handling for marshalling perl subroutines as callbacks.
  934. This is specially tuned for use with GSignal and stuff like io watch,
  935. timeout, and idle handlers.
  936.  
  937. For generic callback functions, which need parameters but do not get
  938. registered with the type system, this is sometimes overkill.  See
  939. GPerlCallback, below.
  940.  
  941. =over
  942.  
  943. =cut
  944.  
  945. =item GClosure * gperl_closure_new (SV * callback, SV * data, gboolean swap)
  946.  
  947. Create and return a new GPerlClosure.  I<callback> and I<data> will be copied
  948. for storage; I<callback> must not be NULL.  If I<swap> is TRUE, I<data> will be
  949. swapped with the instance during invocation (this is used to implement
  950. g_signal_connect_swapped()).
  951.  
  952. If compiled under a thread-enabled perl, the closure will be created and
  953. marshaled in such a way as to ensure that the same interpreter which created
  954. the closure will be used to invoke it.
  955.  
  956. =cut
  957.  
  958. =item GClosure * gperl_closure_new_with_marshaller (SV * callback, SV * data, gboolean swap, GClosureMarshal marshaller)
  959.  
  960. Like C<gperl_closure_new>, but uses a caller-supplied marshaller.  This is
  961. provided for use in those sticky circumstances when you just can't do it 
  962. any other way; in general, you want to use the default marshaller, which you
  963. get if you provide NULL for I<marshaller>.
  964.  
  965. If you use you own marshaller, you need to take care of everything yourself,
  966. including swapping the instance and data if C<GPERL_CLOSURE_SWAP_DATA
  967. (closure)> is true, calling C<gperl_run_exception_handlers> if ERRSV is true
  968. after invoking the perl sub, and ensuring that you properly use the
  969. C<marshal_data> parameter as the perl interpreter when PERL_IMPLICIT_CONTEXT is
  970. defined.  See the implementation of the default marshaller,
  971. C<gperl_closure_marshal>, in Glib/GClosure.xs for inspiration.
  972.  
  973. =cut
  974.  
  975. =back
  976.  
  977. =head2 GPerlCallback
  978.  
  979. generic callback functions usually get invoked directly, and are not passed
  980. parameter lists as GValues.  we could very easily wrap up such generic
  981. callbacks with something that converts the parameters to GValues and then
  982. channels everything through GClosure, but this has two problems:  1) the above
  983. implementation of GClosure is tuned to marshalling signal handlers, which
  984. always have an instance object, and 2) it's more work than is strictly
  985. necessary.
  986.  
  987. additionally, generic callbacks aren't always kind to the GClosure paradigm.
  988.  
  989. so, here's GPerlCallback, which is designed specifically to run generic
  990. callback functions.  it reads parameters off the C stack and converts them into
  991. parameters on the perl stack.  (it uses the GValue to/from SV mechanism to do
  992. so, but doesn't allocate any temps on the heap.)  the callback object itself
  993. stores the parameter type list.
  994.  
  995. unfortunately, since the data element is always last, but the number of
  996. arguments is not known until we have the callback object, we can't pass
  997. gperl_callback_invoke directly to functions requiring a callback; you'll have
  998. to write a proxy callback which calls gperl_callback_invoke.
  999.  
  1000. =over
  1001.  
  1002. =item GPerlCallback * gperl_callback_new (SV * func, SV * data, gint n_params, GType param_types[], GType return_type)
  1003.  
  1004. Create and return a new GPerlCallback; use gperl_callback_destroy when you are
  1005. finished with it.
  1006.  
  1007. I<func>: perl subroutine to call.  this SV will be copied, so don't worry about
  1008. reference counts.  must B<not> be #NULL.
  1009.  
  1010. I<data>: scalar to pass to I<func> in addition to all other arguments.  the SV
  1011. will be copied, so don't worry about reference counts.  may be #NULL.
  1012.  
  1013. I<n_params>: the number of elements in I<param_types>.
  1014.  
  1015. I<param_types>: the #GType of each argument that should be passed from the
  1016. invocation to I<func>.  may be #NULL if I<n_params> is zero, otherwise it must
  1017. be I<n_params> elements long or nasty things will happen.  this array will be
  1018. copied; see gperl_callback_invoke() for how it is used.
  1019.  
  1020. I<return_type>: the #GType of the return value, or 0 if the function has void
  1021. return.
  1022.  
  1023. =cut
  1024.  
  1025. =item void gperl_callback_destroy (GPerlCallback * callback)
  1026.  
  1027. Dispose of I<callback>.
  1028.  
  1029. =cut
  1030.  
  1031. =item void gperl_callback_invoke (GPerlCallback * callback, GValue * return_value, ...)
  1032.  
  1033. Marshall the variadic parameters according to I<callback>'s param_types, and
  1034. then invoke I<callback>'s subroutine in scalar context, or void context if the
  1035. return type is G_TYPE_VOID.  If I<return_value> is not NULL, then value
  1036. returned (if any) will be copied into I<return_value>.
  1037.  
  1038. A typical callback handler would look like this:
  1039.  
  1040.   static gint
  1041.   real_c_callback (Foo * f, Bar * b, int a, gpointer data)
  1042.   {
  1043.           GPerlCallback * callback = (GPerlCallback*)data;
  1044.           GValue return_value = {0,};
  1045.           gint retval;
  1046.           g_value_init (&return_value, callback->return_type);
  1047.           gperl_callback_invoke (callback, &return_value,
  1048.                                  f, b, a);
  1049.           retval = g_value_get_int (&return_value);
  1050.           g_value_unset (&return_value);
  1051.           return retval;
  1052.   }
  1053.  
  1054.  
  1055.  
  1056. =cut
  1057.  
  1058. =back
  1059.  
  1060. =head2 Exception Handling
  1061.  
  1062. Like Event, Tk, and most other callback-using, event-based perl modules,
  1063. Glib traps exceptions that happen in callbacks.  To enable your code to
  1064. do something about these exceptions, Glib stores a list of exception
  1065. handlers which will be called on the trapped exceptions.  This is
  1066. completely distinct from the $SIG{__DIE__} mechanism provided by Perl
  1067. itself, for various reasons (not the least of which is that the Perl
  1068. docs and source code say that $SIG{__DIE__} is intended for running as
  1069. the program is about to exit, and other behaviors may be removed in the
  1070. future (apparently a source of much debate on p5p)).
  1071.  
  1072. =over
  1073.  
  1074. =cut
  1075.  
  1076. =item int gperl_install_exception_handler (GClosure * closure)
  1077.  
  1078. Install a GClosure to be executed when gperl_closure_invoke() traps an
  1079. exception.  The closure should return boolean (TRUE if the handler should
  1080. remain installed) and expect to receive a perl scalar.  This scalar will be
  1081. a private copy of ERRSV ($@) which the handler can mangle to its heart's
  1082. content.
  1083.  
  1084. The return value is an integer id tag that may be passed to
  1085. gperl_removed_exception_handler().
  1086.  
  1087. =cut
  1088.  
  1089. =item void gperl_remove_exception_handler (guint tag)
  1090.  
  1091. Remove the exception handler identified by I<tag>, as returned by
  1092. gperl_install_exception_handler().  If I<tag> cannot be found, this
  1093. does nothing.
  1094.  
  1095. WARNING:  this function locks a global data structure, so do NOT call
  1096. it recursively.  also, calling this from within an exception handler will
  1097. result in a deadlock situation.  if you want to remove your handler just
  1098. have it return FALSE.
  1099.  
  1100. =cut
  1101.  
  1102. =item void gperl_run_exception_handlers (void)
  1103.  
  1104. Invoke whatever exception handlers are installed.  You will need this if
  1105. you have written a custom marshaler.  Uses the value of the global ERRSV.
  1106.  
  1107. =cut
  1108.  
  1109. =back
  1110.  
  1111. =cut
  1112.  
  1113. =head2 GSignal
  1114.  
  1115. =over
  1116.  
  1117. =cut
  1118.  
  1119. =item void gperl_signal_set_marshaller_for (GType instance_type, char * detailed_signal, GClosureMarshal marshaller)
  1120.  
  1121. You need this function only in rare cases, usually as workarounds for bad
  1122. signal parameter types or to implement writable arguments.  Use the given
  1123. I<marshaller> to marshal all handlers for I<detailed_signal> on
  1124. I<instance_type>.  C<gperl_signal_connect> will look for marshallers
  1125. registered here, and apply them to the GPerlClosure it creates for the given
  1126. callback being connected.
  1127.  
  1128. Use the helper macros in gperl_marshal.h to help write your marshaller
  1129. function.  That header, which is installed with the Glib module but not
  1130. #included through gperl.h, includes commentary and examples which you
  1131. should follow closely to avoid nasty bugs.  Use the Source, Luke.
  1132.  
  1133. WARNING: Bend over backwards and turn your head around 720 degrees before
  1134. attempting to write a GPerlClosure marshaller without using the macros in
  1135. gperl_marshal.h.  If you absolutely cannot use those macros, be certain to
  1136. understand what those macros do so you can get the semantics correct, and
  1137. keep your code synchronized with them, or you may miss very important
  1138. bugfixes.
  1139.  
  1140. =cut
  1141.  
  1142. =item gulong gperl_signal_connect (SV * instance, char * detailed_signal, SV * callback, SV * data, GConnectFlags flags)
  1143.  
  1144. The actual workhorse behind GObject::signal_connect, the binding for
  1145. g_signal_connect, for use from within XS.  This creates a C<GPerlClosure>
  1146. wrapper for the given I<callback> and I<data>, and connects that closure to the
  1147. signal named I<detailed_signal> on the given GObject I<instance>.  This is only
  1148. good for named signals.  I<flags> is the same as for g_signal_connect().
  1149. I<data> may be NULL, but I<callback> must not be.
  1150.  
  1151. Returns the id of the installed callback.
  1152.  
  1153. =cut
  1154.  
  1155. =back
  1156.  
  1157. =cut
  1158.  
  1159.  
  1160. =head1 SEE ALSO
  1161.  
  1162. perlapi(1), perlguts(1), GLib Reference Manual, Glib(3pm), Glib::devel(3pm).
  1163.  
  1164. =head1 AUTHORS
  1165.  
  1166. This file was automatically generated from the source code of the Glib module,
  1167. which is maintained by the gtk2-perl team.
  1168.  
  1169. =head1 LICENSE
  1170.  
  1171. Copyright (C) 2003 by the gtk2-perl team (see the file AUTHORS for the
  1172. full list)
  1173.  
  1174. This library is free software; you can redistribute it and/or modify it under
  1175. the terms of the GNU Library General Public License as published by the Free
  1176. Software Foundation; either version 2.1 of the License, or (at your option) any
  1177. later version.
  1178.  
  1179. This library is distributed in the hope that it will be useful, but WITHOUT ANY
  1180. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  1181. PARTICULAR PURPOSE.  See the GNU Library General Public License for more
  1182. details.
  1183.  
  1184. You should have received a copy of the GNU Library General Public License along
  1185. with this library; if not, write to the Free Software Foundation, Inc., 
  1186. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  1187.  
  1188. =cut
  1189.